use super::*;

pub struct ConnectCmd<'a> {
  socket: &'a str,
  cust_err: Option<&'a str>,
}

impl<'a> ConnectCmd<'a> {
  pub fn new(socket: &'a str, cust_err: Option<&'a str>) -> Self {
    return ConnectCmd { socket, cust_err };
  }
}

impl<'a> BinaryCommand for ConnectCmd<'a> {
  type Output = ();
  fn exec(&self) -> Self::Output {
    if cfg!(target_os = "windows") {
      panic!("no impl for windows!")
    } else {
      let output = Command::new(ADB_BIN)
        .arg("connect")
        .arg(self.socket)
        .output();
      self.process_stdout::<&str>(
        output,
        Some(&["failed to connect to", "already connected to"]),
        self.cust_err,
      );
    }
  }
}

pub struct DisconnectCmd<'a> {
  socket: Option<&'a str>,
  cust_err: Option<&'a str>,
}

impl<'a> DisconnectCmd<'a> {
  pub fn new(socket: Option<&'a str>, cust_err: Option<&'a str>) -> Self {
    return DisconnectCmd { socket, cust_err };
  }
}

impl<'a> BinaryCommand for DisconnectCmd<'a> {
  type Output = ();
  fn exec(&self) -> Self::Output {
    if cfg!(target_os = "windows") {
      panic!("no impl for windows!")
    } else {
      let output = Command::new(ADB_BIN)
        .arg("disconnect")
        .arg(self.socket.unwrap_or(""))
        .output();
      self.process_stdout::<&str>(output, None, self.cust_err);
    }
  }
}
